<template>
    <view class="pull-goods-wrap">
        <view class="like-title">
            <view class="line line-l"></view>
            你可能还喜欢
            <view class="line line-r"></view>
        </view>
        <view class="goods-item" v-for="(g,i) in goods" :key="i" >
            <sp-goods-card :goods="g"></sp-goods-card>
        </view>
    </view>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from "vue"
import { onReachBottom } from "@dcloudio/uni-app";
import { post } from "@/libs/request"
//商品列表
const goods = ref([])
let formData = reactive({
  query: {
    pageIndex: 1,
    pageSize: 10,
  },
  // 是否还有下一页
  isNext: true
})
//获取订单列表
const queryGoodsList = () => {
  post("goods/paginate",formData.query).then((res:any)=>{
    if(res.errCode==0){
      goods.value = goods.value.concat(res.data)
      formData.query.pageIndex++
      if(goods.value.length === res.page.total){
          formData.isNext = false
      }
    }
  })
};

onMounted(() => {
  formData.query.pageIndex = 1
  formData.isNext = true
  goods.value = []
  queryGoodsList()
})

onReachBottom(() => {
  formData.isNext && queryGoodsList()
})
</script>
<style lang="less" scoped>
    .pull-goods-wrap {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .like-title{
        display: flex;
        -webkit-box-align: center;
        -ms-flex-align: center;
        align-items: center;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        justify-content: center;
        -webkit-box-orient: unset;
        -webkit-box-direction: unset;
        -ms-flex-direction: unset;
        flex-direction: unset;
        height: 90rpx;
        font-size: 32rpx;
        font-weight: bold;
        color: #FC3247;
        width: 100%;
        .line{
            height:2rpx;
            width:56rpx;
            background: #FC3247;
            position: relative;
            &::after{
                content: "";
                width: 10rpx;
                height: 10rpx;
                border-radius: 50%;
                background: #FC3247;
                position: absolute;
                top: 50%;
                transform: translateY(-50%);
            }
            &.line-l{
                margin-right: 20rpx;
            }
            &.line-r{
                margin-left: 20rpx;
            }
            &.line-l::after{
                right:0;
            }
            &.line-r::after{
                left:0;
            }
        }
      }
      .goods-item{
        width: 346rpx;
        margin-bottom: 20rpx;
      }
      :deep(.goods-card--col .goods-card-cover) {
        width: 100%;
        height: 260rpx;
        border-radius: 15rpx;
      }
    }
</style>